package org.thomias.exo1.checksum;
import java.io.FileInputStream;
import java.security.MessageDigest;

public class Sha1 {
	public static void main(String[] args) {
		try {
			String file = "image.jpg";
			FileInputStream inFile = null;
			try {
				MessageDigest md = MessageDigest.getInstance("SHA-512");
				inFile = new FileInputStream(file);
				byte[] array = new byte[1024];
				while (inFile.read(array) != -1) {
					md.update(array);
				}
				byte[] hash = md.digest();
				System.out.println("Hash length: " + hash.length);
				String result = "";
				for (int i = 0; i < hash.length; i++) {
					result += String.format("%x", hash[i]);
				}
				System.out.println("Hash = " + result);
			} finally {
				if (inFile != null) {
					inFile.close();
				}

			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
